/*
 * Yet Another Haxe Library, Copyright (c) 2009, Jean-Philippe CIMAN (Jeanffy)
 * All rights reserved.
 * Permission is hereby granted to use, copy, modify, and distribute this
 * source code, or portions hereof, for any purpose, without fee, subject
 * to the following restrictions:
 *
 * 1. The origin of this source code must not be misrepresented.
 * 2. Altered versions must be plainly marked as such and
 *    must not be misrepresented as being the original source.
 * 3. This copyright notice may not be removed or altered from
 *    any source or altered source distribution.
 *
 * If you use this source code in a product, acknowledgment is not
 * required but would be appreciated.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE PROJECT AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
	This class implements a rectangle area
**/
class YahRect
{
	public var xmin:Float;
	public var ymin:Float;
	public var xmax:Float;
	public var ymax:Float;
	
	public function new(?_xmin:Float, ?_ymin:Float, ?_xmax:Float, ?_ymax:Float)
	{
		xmin = 0;
		if (_xmin != null)
			xmin = _xmin;
		ymin = 0;
		if (_ymin != null)
			ymin = _ymin;
		xmax = 0;
		if (_xmax != null)
			xmax = _xmax;
		ymax = 0;
		if (_ymax != null)
			ymax = _ymax;
	}
	
	/** Defines the rectangle **/
	public function set(_xmin:Float, _ymin:Float, _xmax:Float, _ymax:Float)
	{
		xmin = _xmin;
		ymin = _ymin;
		xmax = _xmax;
		ymax = _ymax;
	}
	
	/** Tests if another rectangle is inside **/
	public function isInRect(_xmin:Float, _ymin:Float, _xmax:Float, _ymax:Float) : Bool
	{
		if (xmin > _xmax)
			return false;
		if (xmax < _xmin)
			return false;
		if (ymin > _ymax)
			return false;
		if (ymax < _ymin)
			return false;
		return true;
	}
	
	/** Tests if another rectangle is inside **/
	public function isInRect2(rect:YahRect) : Bool
	{
		return isInRect(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
	}
	
	/** Tests if a point is inside **/
	public function ptIsInRect(x:Float, y:Float)
	{
		return isInRect(x, y, x, y); // TODO not optimized...
	}
	
#if debug
	/** Debug only. Traces the rectangle **/
	public function dump()
	{
		trace("YahRect : (" + xmin + ", " + ymin + ") > (" + xmax + ", " + ymax + ")");
	}
#end
}
 
